﻿#pragma once
#include "AsQBasicGlobal.h"

class AS_QBASIC_EXPORT AsCall : public QObject {
	Q_OBJECT

private:
	AsCall(QObject* receiver);
	~AsCall();
	QObject* mReceiver;

private:
	template <typename _Slot>
	void call(_Slot slot, Qt::ConnectionType type = Qt::AutoConnection) {
		connect(this, &AsCall::sigCall, mReceiver, slot, type);
		emit sigCall();
		this->deleteLater();
	}

signals:
	void sigCall();

public:
	template <typename _Slot>
	static void execute(QObject* object, _Slot slot, Qt::ConnectionType type = Qt::AutoConnection) {
		AsCall* c = new AsCall(object);
		c->moveToThread(object->thread());
		c->call(slot, type);
	}

};